
var chars = '0123456789abcdefghijklmnopqrstuvwxyz'
var common = require('./common.js');
var agent_index = 0;
var process_index = 0;
var master_addr = '127.0.0.1:8123';
var case_name = 'test';

module.exports.getAgentIndex = function () {
    return agent_index;
}

module.exports.getProcessIndex = function () {
    return process_index;
}

module.exports.getCaseName = function () {
    return case_name;
}

module.exports.genUsername = function (index, pindex, aindex) {
    if(aindex==null) aindex = agent_index;
    if(pindex==null) pindex = process_index;
    if(index==null) index = 0;

    var len = chars.length;
    var ret = '';
    while(index>0) {
        var k = index % len;
        index = (index - k) / len;
        ret += chars.substring(k, k+1);
    }
    while(ret.length<6) {
        ret = '0' + ret;
    }
    while(pindex>0) {
        var k = pindex % len;
        pindex = (pindex - k) / len;
        ret += chars.substring(k, k+1);
    }
    while(ret.length<8) {
        ret = '0' + ret;
    }
    while(aindex>0) {
        var k = aindex % len;
        aindex = (aindex - k) / len;
        ret += chars.substring(k, k+1);
    }
    while(ret.length<10) {
        ret = '0' + ret;
    }
    return ret;
};

module.exports.init = function () {
    var args_methods = {
        'master_addr' : function(v) { master_addr = v; },
        'agent_index' : function(v) { agent_index = v; },
        'process_index' : function(v) { process_index = v; },
        'case' : function(v) { case_name = v; },
    };
    common.parseArgs();
    common.processArgs(args_methods);
    common.setMasterAddr(master_addr);
};
